var mapIds = [867236100, 867236150, 867236200, 867236220, 867236250, 867236300];
var 准备地图 = 867236000;
var 副本名称 = "朱丽埃塔";
var BOSS_1_id = 9402279;
var BOSS_1_血量倍率 = 1;
var 副本时限 = 1000 * 60 * 30;
var 退场倒计时 = 300;

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance("副本_莫奈德_Act3_Boss");
    for (var b = 0; b < mapIds.length; b++) {
        var e = c.setInstanceMap(mapIds[b]);
        e.resetFully();
        e.killAllMonsters(true)
    }
    c.setProperty("LogName", "副本_莫奈德_Act3_Boss");
    c.setProperty("FBtime", 副本时限);
    c.setProperty("FBname", 副本名称);
    var d = em.getMonster(BOSS_1_id).getMobMaxHp() * BOSS_1_血量倍率;
    c.setProperty("BOSShp", d);
    c.setProperty("strMap", 准备地图);
    return c
}

function onPlayerRegistered(b, a) {
    a.setReviveCount(50);
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0));
    b.startEventTimer(30 * 60 * 1000);
    em.setProperty("death_" + a.getId(), 0);
    a.getAPI().setNumberForQuestInfo(64272, "damage2", 0);
    a.getAPI().setNumberForQuestInfo(准备地图, "damage", 0)
}

function onPlayerRevived(c, b) {
    b.eventRevive();
    b.forceRevive();
    b.getAPI().playerMessage(-1, "在亚皮纳斯的祝福下复活，恢复了全部的体力。");
    b.getAPI().addPopupSay(9400584, 1000, "#face0#亚皮纳斯的祝福与你同在……", "", 0);
    if (b.getMapId() == 867236150) {
        if (cm.getNumberFromQuestInfo(64204, "LadderMob") == 1) {
            b.getAPI().onTeleport(4, b.getId(), -86, 351)
        } else {
            if (cm.getNumberFromQuestInfo(64204, "LadderMob") == 2) {
                b.getAPI().onTeleport(4, b.getId(), 142, 23)
            }
        }
    }
    var a = parseInt(em.getProperty("death_" + b.getId())) + 1;
    em.setProperty("death_" + b.getId(), a + "");
    return true
}

function onMapChanged(c, b, a) {
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    if (a == 867236250) {
        c.schedule("end", 60 * 1000)
    }
    em.setProperty("kill", "0");
    em.setProperty("clear", "0");
    em.setProperty("curMap", a)
}

function end() {
    em.getMapFactoryMap(867236250).startSimpleMapEffect("是时候离开城门了，在城外决一死战吧。", 5120180);
    em.setProperty("clear", "1")
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onMonsterKilled(a, b) {
    a.getPlayers().forEach(function (e) {
        if (e.getMapId() == 867236220) {} else {
            if (b == 9402270 || b == 9402271 || b == 9402272) {
                e.getAPI().warp(867236150, 0, false)
            } else {
                if (b == 9402275) {
                    e.getAPI().warp(867236220, 0, true)
                } else {
                    if (b == 9402277) {
                        e.getAPI().warp(867236300, 0, true)
                    } else {
                        if (b == 9402279) {
                            if (e.getAPI().isQuestFinished(64140)) {
                                openNpc(a, 9130027, "评价系统");
                                a.startEventTimer(1 * 60 * 1000);
                                for (var d = 0; d < a.getPlayerCount(); d++) {
                                    a.getPlayers().get(d).getAPI().fieldEffect_ScreenMsg("monsterPark/clear");
                                    a.getPlayers().get(d).getAPI().fieldEffect_PlayFieldSound("Party1/Clear", 100)
                                }
                            } else {
                                e.forceCompleteQuest(64140);
                                e.updateInfoQuest(64270, "4=1");
                                e.updateInfoQuest(64271, "5=1;6=1");
                                e.changeMap(867202910, 0)
                            }
                            e.getAPI().addNumberForQuestInfo(64270, "5", 1);
                            e.getAPI().addNumberForQuestInfo(64272, "21", 1);
                            var c = parseInt(em.getProperty("death_" + e.getId()));
                            if (c == 0) {
                                e.getAPI().addNumberForQuestInfo(64272, "22", 1)
                            }
                            if (e.getAPI().getNumberFromQuestInfo(64272, "damage2") == 0) {
                                e.getAPI().addNumberForQuestInfo(64272, "30", 1)
                            }
                        } else {
                            if (b == 9402322 || b == 9402328) {
                                e.getAPI().addNumberForQuestInfo(64270, "6", 1);
                                e.getAPI().addNumberForQuestInfo(64271, "7", 1)
                            }
                        }
                    }
                }
            }
        }
    });
    return 1
}

function onMonsterDamaged(b, a, e, f, c) {
    if (a.getMapId() == 867236220) {
        return
    }
    var d = a.getMap().getMonsterById(e);
    b.setProperty("bossHP", Math.max(d.getMobMaxHp() / 100, d.getHp()));
    a.getAPI().addNumberForQuestInfo(准备地图, "damage", f)
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onItemPickedUp(b, a, c) {};